home *** CD-ROM | disk | FTP | other *** search
/ The Fatted Calf / The Fatted Calf.iso / Applications / Utilities / Pastry / DeveloperNotes / sample / SoundSamplePane.m < prev   
Encoding:
Text File  |  1994-02-28  |  2.0 KB  |  120 lines

  1.  
  2. //
  3. //  This is just a sample pane for Pastry.  This source is in the public
  4. //  domain.  Someone with more knowledge of the SoundKit can write a
  5. //  much nicer sound inspector pane.
  6. //
  7.  
  8.  
  9. #import "SoundSamplePane.h"
  10.  
  11. static NXAtom    types[2] = {NULL};
  12.  
  13. @implementation SoundSamplePane
  14.  
  15. - _loadNib
  16. {
  17.     char    buf[MAXPATHLEN+1];
  18.  
  19.     // Load a nib file from the bundle
  20.  
  21.     [[NXBundle bundleForClass: [self class]]
  22.               getPath: buf
  23.           forResource: "Sound"
  24.                ofType: "nib"];
  25.  
  26.     [NXApp loadNibFile: buf
  27.          owner: self
  28.          withNames: NO
  29.           fromZone: [self zone]];
  30.  
  31.     view = [window setContentView:[[View alloc] init]];
  32.     [window free];
  33.     window = nil;
  34.     return self;
  35. }
  36.  
  37.  
  38. + initialize
  39. {
  40.     if (!types[0]) {
  41.     types[0] = NXSoundPboardType;
  42.     types[1] = NULL;
  43.     }
  44.     return self;
  45. }
  46.  
  47.  
  48. + (const NXAtom *)types
  49. {
  50.     return types;
  51. }
  52.  
  53.  
  54. - free
  55. {
  56.     [sound free];
  57.     [view free];
  58.     return [super free];
  59. }
  60.  
  61.  
  62. - (View *)view
  63. {
  64.     if (!view)
  65.     [self _loadNib];
  66.     return view;
  67. }
  68.  
  69.  
  70. - updateFromStream:(NXStream *)stream withType:(NXAtom)type
  71. {
  72.     // This seems like kind of a hacked way to get sound from a stream
  73.     // that was written from the pasteboard data, but I don't know
  74.     // enough about the sound kit to init a sound straight from the
  75.     // stream.  I just use Sound's -initFromPasteboard: method.
  76.  
  77.     Pasteboard *p = [Pasteboard newUnique];
  78.  
  79.     if (!view)
  80.         [self _loadNib];
  81.  
  82.     [p declareTypes:types num:1 owner:self];
  83.     [p writeType:type fromStream:stream];    //! We should handle exceptions
  84.  
  85.     [sound free];
  86.     sound = [[Sound alloc] initFromPasteboard:p];
  87.     [p freeGlobally];
  88.  
  89.     [sound setDelegate:self];
  90.     [durationField setDoubleValue:[sound duration]];
  91.     [statusField setStringValue:"not playing"];
  92.     return self;
  93. }
  94.  
  95.  
  96.  
  97. - play:sender
  98. {
  99.     if (!playButton)
  100.     playButton = sender;
  101.  
  102.     if (sound) {
  103.     [playButton setEnabled:NO];
  104.     [statusField setStringValue:"playing"];
  105.     [sound play:self];
  106.     }
  107.     return self;
  108. }
  109.  
  110.  
  111. - didPlay:sender
  112. {
  113.     [playButton setEnabled:YES];
  114.     [statusField setStringValue:"not playing"];
  115.     return self;
  116. }
  117.  
  118.  
  119. @end
  120.